package com.luyuan.yuansousuo.controller;

import com.luyuan.yuansousuo.common.BaseResponse;
import com.luyuan.yuansousuo.common.ResultUtils;
import com.luyuan.yuansousuo.manager.SearchFade;
import com.luyuan.yuansousuo.model.dto.search.SearchRequestParam;
import com.luyuan.yuansousuo.model.vo.SearchVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {

    @Resource
    private SearchFade searchFade;

    /**
     * 搜索所有数据 异步方式
     *
     * @param searchRequest
     * @param request
     * @return
     */
    @RequestMapping("/all")
    public BaseResponse<SearchVO> searchAll(@RequestBody SearchRequestParam searchRequest, HttpServletRequest request) {
        return ResultUtils.success(searchFade.searchAll(searchRequest, request));
    }
//    @Resource
//    private UserService userService;
//    @Resource
//    private PostService postService;
//    @Resource
//    private PictureService pictureService;
    /**
     * 搜索所有数据 同步方式
     * @param searchRequest
     * @param request
     * @return
     */
//    @RequestMapping("/all")
//    public BaseResponse<SearchVO> searchAll(@RequestBody SearchRequestParam searchRequest, HttpServletRequest request){
//        log.info("search all request:{}", searchRequest);
//        // 获取请求参数内容
//        String searchText = searchRequest.getSearchText();
//        int current = searchRequest.getCurrent();
//        int pageSize = searchRequest.getPageSize();
//
//        // 查询用户数据
//        UserQueryRequest userQueryRequest = new UserQueryRequest();
//        userQueryRequest.setUserName(searchText);
//        userQueryRequest.setCurrent(current);
//        userQueryRequest.setPageSize(pageSize);
//        Page<UserVO> userVOPage = userService.listUserVOByPage(userQueryRequest);
//        List<UserVO> userVOList = userVOPage.getRecords();
//
//        // 查询帖子数据
//        PostQueryRequest postQueryRequest = new PostQueryRequest();
//        postQueryRequest. setSearchText(searchText);
//        postQueryRequest.setCurrent(current);
//        Page<PostVO> postVOPage = postService.listPostVOByPage(postQueryRequest, request);
//        List<PostVO> postRecordList = postVOPage.getRecords();
//
//        // 查询图片数据
//        Page<Picture> picture = pictureService.searchPicture(searchText, current, pageSize);
//        List<Picture> pictureList = picture.getRecords();
//
//        // 构造返回结果
//        SearchVO searchVO = new SearchVO();
//        searchVO.setUserList(userVOList);
//        searchVO.setPostList(postRecordList);
//        searchVO.setPictureList(pictureList);
//
//        return ResultUtils.success(searchVO);
//    }
}
